import { getConfig } from './config.js';
import { FlashcoreFileAdapter } from './flashcore-fs.js';
import { Globals } from './globals.js';
import { logger } from './logger.js';

const t=new Map,u={clear:()=>Globals.getFlashcoreAdapter().clear(),delete:(e,a)=>{if(a?.namespace&&(e=Array.isArray(a.namespace)?`${a.namespace.join("/")}__${e}`:`${a.namespace}__${e}`),t.has(e)){const r=Globals.getFlashcoreAdapter().get(e);if(r instanceof Promise)return r.then(n=>{t.get(e).forEach(c=>c(n,void 0));}).then(()=>Globals.getFlashcoreAdapter().delete(e)).catch(()=>Globals.getFlashcoreAdapter().delete(e));t.get(e).forEach(n=>n(r,void 0));}return Globals.getFlashcoreAdapter().delete(e)},get:(e,a)=>(a?.namespace&&(e=Array.isArray(a.namespace)?`${a.namespace.join("/")}__${e}`:`${a.namespace}__${e}`),Globals.getFlashcoreAdapter().get(e)??a?.default),has:(e,a)=>(a?.namespace&&(e=`${a.namespace}__${e}`),Globals.getFlashcoreAdapter().has(e)),off:(e,a,r)=>{r?.namespace&&(e=Array.isArray(r.namespace)?`${r.namespace.join("/")}__${e}`:`${r.namespace}__${e}`),t.has(e)&&a?(t.get(e)?.delete(a),t.get(e)?.size===0&&t.delete(e)):t.has(e)&&t.delete(e);},on:(e,a,r)=>{r?.namespace&&(e=Array.isArray(r.namespace)?`${r.namespace.join("/")}__${e}`:`${r.namespace}__${e}`),t.has(e)||t.set(e,new Set),t.get(e)?.add(a);},set:(e,a,r)=>{if(r?.namespace&&(e=Array.isArray(r.namespace)?`${r.namespace.join("/")}__${e}`:`${r.namespace}__${e}`),t.has(e)||typeof a=="function"){const n=Globals.getFlashcoreAdapter().get(e),c=async o=>{let i=a;return typeof a=="function"&&(i=a(o)),t.has(e)&&t.get(e).forEach(h=>h(o,i)),Globals.getFlashcoreAdapter().set(e,i)};return n instanceof Promise?n.then(async o=>await c(o)).catch(()=>Globals.getFlashcoreAdapter().set(e,a)):c(n)}return Globals.getFlashcoreAdapter().set(e,a)}};async function A(){const e=getConfig();if(e.flashcore?.keyv)try{logger.debug("Using Keyv Flashcore adapter");const a=(await import('keyv')).default,r=new a(e.flashcore.keyv);r.on("error",n=>{logger.error("Keyv error:",n);}),Globals.registerFlashcore(r);}catch(a){throw logger.error(a),new Error("Failed to import or setup the adapter with keyv package.")}else Globals.registerFlashcore(new FlashcoreFileAdapter),await Globals.getFlashcoreAdapter().init();}

export { u as Flashcore, A as prepareFlashcore };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=flashcore.js.map